package model;

import java.sql.*;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Vector;
import object.Producer;
import object.ReturnBool;
import tpInterface.IProducer;

/**
 *
 * @author SonTT
 */
public class ProducerM implements IProducer {

    private TPConnection tPConnection;

    public ProducerM() {
    }

    public static Iterator getProducers(String test) {
        String driveString = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        String url = "jdbc:sqlserver://localhost:1433; databasename=tech-pro";
        String username = "sa";
        String password = "fat123456";

        Vector<Producer> producers = new Vector<Producer>();
        try {
            Class.forName(driveString);
            Connection connection = DriverManager.getConnection(url, username, password);
            Statement stm = connection.createStatement();
            String query = "SELECT * FROM Producer";
            ResultSet rs = stm.executeQuery(query);

            if (rs.wasNull()) {
                return null;
            } else {
                while (rs.next()) {

                    Producer pd = new Producer(
                            rs.getInt(1),
                            rs.getNString(2),
                            rs.getNString(3),
                            rs.getDate(5));
                    producers.addElement(pd);
                }

                return producers.iterator();
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ProductM.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } catch (SQLException ex) {
            Logger.getLogger(ProductM.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    @Override
    public List<Producer> getProducers() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ReturnBool addProducer(Producer producer) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ReturnBool editProducer(Producer producer) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ReturnBool deleteProducer(String producerID) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ReturnBool deleteProducers(String[] producerIDs) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Producer> searchProducer(String keyword) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    private static final Logger LOG = Logger.getLogger(ProducerM.class.getName());
}
